<?php
session_start();
if (isset($_POST['openid']) && !empty($_POST['openid'])){
    include '../c/config.php';
    include 'thearray.php';
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    if (!$mysqli->set_charset("utf8")) {}
    $openid=addslashes(trim($_POST['openid']));
    $type=addslashes(trim($_POST['type']));
    
    $sai=array();
    if (2 == $type){
        $baoId=array();
        $query=$mysqli->query("SELECT sid FROM baoming where openid='".$openid."' ");
        while ($list=$query->fetch_assoc()){
            $baoId[]=$list['sid'];
        }
        $query=$mysqli->query("SELECT id,name FROM saisi where isopen=1  ");
        while ($list=$query->fetch_assoc()){
            $hasbao='';
            if (in_array($list['id'], $baoId)){
                $hasbao='y';
            }
            $sai[]=array('id'=>$list['id'],'name'=>$list['name'],'hsb'=>$hasbao);
        }
    }
    if (1 == $type){
        $query=$mysqli->query("SELECT id,name FROM saisi where isopen=1 or isopen=2 ");
        while ($list=$query->fetch_assoc()){
            $sai[]=$list;
        }
    }
    if (3 == $type){
        $query=$mysqli->query("SELECT id,name FROM saisi where isopen=3 ");
        while ($list=$query->fetch_assoc()){
            $sai[]=$list;
        }
    }
    
    
    $mysqli->close();
    
    echo json_encode(array('u'=>$user,'s'=>$sai));
}

